﻿//pbf矢量切片服务
function TilePbfService(layerInfo) {
    var TilePbfService = new Object;
    TilePbfService.id = layerInfo.hasOwnProperty("GUID") ? layerInfo.GUID : "";
    TilePbfService.url = layerInfo.hasOwnProperty("URL") ? layerInfo.URL : "";
    TilePbfService.name = layerInfo.hasOwnProperty("NAME") ? layerInfo.NAME : "";
    TilePbfService.servertype = layerInfo.hasOwnProperty("SERVERTYPE") ? layerInfo.SERVERTYPE : "";
    TilePbfService.prj = layerInfo.hasOwnProperty("PRJ") ? layerInfo.PRJ : "EPSG:3857";
    TilePbfService.maxzoom = layerInfo.hasOwnProperty("MAXZOOM") ? layerInfo.MAXZOOM : "22";
    TilePbfService.params = layerInfo.hasOwnProperty("PARAMETERS") ? layerInfo.PARAMETERS : "";
    TilePbfService.defaultstyle = layerInfo.hasOwnProperty("DEFAULTSTYLE") ? layerInfo.DEFAULTSTYLE : SWPolygonStyle.BluePolygon;
    TilePbfService.CreateLayer = function () {
        var id = this.id;
        var url = this.url;
        var name = this.name;
        var servertype = this.servertype;
        var prj = this.prj;
        var maxzoom = this.maxzoom;
        var params = this.params;
        var defaultstyle = this.defaultstyle;
        var projection4326 = new ol.proj.Projection({
            code: prj,
            axisOrientation: 'neu'
        });
        var source4326 = new ol.source.VectorTile({
            tilePixelRatio: 1, // 
            tileGrid: new ol.tilegrid.createXYZ({ maxZoom: maxzoom }),
            format: new ol.format.MVT(),
            url: url + params + '@EPSG%3A3857@pbf/{z}/{x}/{-y}.pbf',
            wrapX: false

        });
        source4326.set("name", name, true);
        source4326.set("id", id, true);
        var thisLayer = new ol.layer.VectorTile({
            style: defaultstyle,
            source: source4326
        });
        return thisLayer;
    }
    return TilePbfService;
}